TCellAlignMenuItemDispatcher.isAvailable   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
dl 0
loc 3
rs 10
1
import { selectionCell, setCellAttr } from 'prosemirror-tables';
2
import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher';
3
import { svgIcon } from '../MDI';
4
import MenuItem from '../MenuItem';
5
6
export default class TCellAlignMenuItemDispatcher extends AbstractMenuItemDispatcher {
7
    constructor(align) {
8
        super();
9
        this.align = align;
10
    }
11
12
    isAvailable(schema) {
13
        return !!schema.nodes.table;
14
    }
15
16
    getMenuItem(schema) {
17
        if (!this.isAvailable(schema)) {
18
            throw new Error('Table not available in schema!');
19
        }
20
21
        return new MenuItem({
22
            command: (state, dispatch) => {
23
                const cell = selectionCell(state);
24
                if (!cell) {
25
                    return false;
26
                }
27
                if (cell.nodeAfter.attrs.align === this.align) {
28
                    return setCellAttr('align', '')(state, dispatch);
29
                }
30
                return setCellAttr('align', this.align)(state, dispatch);
31
            },
32
            icon: svgIcon(`format-align-${this.align}`),
33
            label: LANG.plugins.prosemirror[`label:table-cell-align-${this.align}`],
0 ignored issues
show
Bug introduced by
The variable LANG seems to be never declared. If this is a global, consider adding a /** global: LANG */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
34
            isActive: (state) => {
35
                const cell = selectionCell(state);
36
                if (!cell) {
37
                    return false;
38
                }
39
                return cell.nodeAfter.attrs.align === this.align;
40
            },
41
        });
42
    }
43
}
44